<?php 
/**
 * 加盟商model类
 * @Author    紫梦
 * @DateTime  2017-11-13
 * @copyright 响响租车
 * @version   1.0
 */
namespace app\common\model;
use think\Model;
use traits\model\SoftDelete;


class Agency extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $autoWriteTimestamp = true;
    protected $insert = ['agency_id'];
    
    protected function setAgencyIdAttr()
    {
        return session('admin.agency_id');
    }
    
    // // 定义全局的查询范围
    // protected static function base($query)
    // {
    //     $agency = session('admin.agency_id');
    //     if($agency==1){
    //         $query->where('delete_time',null);

    //     }else{
    //         $query->where(['id'=>$agency,'delete_time'=>null]);

    //     }
                    
    // }

    public function cars()
    {
        return $this->hasMany('Cars','agency_id');
    }
}